<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var str = prompt("请输入需要反转的字");
      // 方法一：先变成数组翻转再变成字符串
      //   console.log(str.split("").reverse().join(""));
      // 方法二：
      var newStr = "";
      for (i = str.length - 1; i >= 0; i--) {
        newStr += str[i];
      }

      console.log(newStr);
    </script>
  </body>
</html>
